<div class="layui-card-header layui-card">
    <span class="layui-breadcrumb" lay-filter="breadcrumb">
        <a href="">首页</a>
        <a><cite>新建二维码</cite></a>
    </span>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">二维码列表信息</li>
            </ul>
            <div class="layui-tab-content">
                <style>
                    .center {
                        width: 80%;
                    }
                </style>

                <form class="layui-form center">
                    <div class="layui-form-item">
                        <label class="layui-form-label">二维码名称</label>
                        <div class="layui-input-block">
                            <input type="text" required  lay-verify="required" placeholder="请输入二维码名称" autocomplete="off" class="layui-input ewmname">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">最小金额</label>
                        <div class="layui-input-block">
                            <input type="text" required  lay-verify="required | number" placeholder="请输入最小金额(元)" autocomplete="off" class="layui-input minM">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">最大金额</label>
                        <div class="layui-input-block">
                            <input type="text" required  lay-verify="required | number" placeholder="请输入最大金额(元)" autocomplete="off" class="layui-input maxM">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">扫码渠道</label>
                        <div class="layui-input-block">
                            <textarea name="channels" class="layui-textarea" id="channels">[{"channelId":"wxpay_jsapi","productId":"8004"},{"channelId":"alipay_wap","productId":"8007"}]</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item ">
                        <div class="layui-input-block">
                            <button type="button" id="save_btn" class="layui-btn">保存</button>
                            <button type="button" id="back_btn" class="layui-btn">返回</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['admin','form'],function(){
        var form = layui.form
        , $ = layui.$
        , admin = layui.admin
        , element = layui.element
        , layer = layui.layer ;

        element.render('breadcrumb', 'breadcrumb');//渲染导航信息

        form.on('checkbox()', function(data){
            if(data.elem.checked){
                $(this).prop('checked',true);
            }else{
                $(this).prop('checked',false);
            }
        }); 

        $('#save_btn').click(function(){
            var apId = layui.router().search.appId;
            var ewmname = $.trim($('.ewmname').val());
            var minM = $.trim($('.minM').val());
            var maxM = $.trim($('.maxM').val());

            var channels = $.trim($('#channels').val());

            admin.req({
                type: 'post',
                url: layui.setter.baseUrl + '/mch_qrcode/add', //模拟接口,
                data: {
                    appId: apId ,
                    channels: channels ,
                    codeName: ewmname,
                    minAmount: minM,
                    maxAmount: maxM
                },
                error: function(err){
                    layer.alert(err);
                },
                success: function(res){
                    if(res.code == '0'){
                        layer.alert(res.msg,{title: '保存成功'},function(index){
                            layer.close(index);
                            location.hash =  "/account/qrcode/list/appId=" + apId;
                        })
                    }
                }
            })
        });

        $('#back_btn').click(function(){
            var apId = layui.router().search.appId;
            location.hash =  "/account/qrcode/list/appId=" + apId;
        });

        form.render();//手动渲染表单
    })
</script>